package com.shujia.spark.mllib

import org.apache.spark.ml.classification.LogisticRegressionModel
import org.apache.spark.ml.linalg.Vectors
import org.apache.spark.sql.SparkSession

object Demo4UsePersonModel {
  def main(args: Array[String]): Unit = {
    val spark: SparkSession = SparkSession
      .builder()
      .master("local")
      .appName("point")
      .getOrCreate()
    import spark.implicits._
    import org.apache.spark.sql.functions._

    /**
     * 1、加载模型
     */

    val model: LogisticRegressionModel = LogisticRegressionModel.load("data/person_model")

    /**
     * 预测
     * 0 1:4.4 2:3.9 3:2.9 4:118.8 5:81.3 6:68.4 7:72
     * 1 1:5.2 2:4.5 3:3.3 4:141.3 5:85.1 6:71.3 7:73
     * 0 1:4.7 2:3.3 3:2.5 4:97.6 5:73.8 6:62.1 7:93
     */

    val y1: Double = model.predict(Vectors.dense(Array(5.2, 4.5, 3.3, 141.3, 85.1, 71.3, 73)))
    println(y1)

  }

}
